import sys

# students = []
# def menu():
#     print('-------------------')
#     print(' 1.新增学生 2.显示学生')
#     print(' 3.删除学生 4.查找学生')
#     print('      0.退出程序    ')
#
# def save():
#     # 用来存档
#     with open('d:/PythonProject/record.txt','w',encoding='utf8') as f:
#         for i in students:
#             f.write(f"{i['stu_id']}\t{i['stu_name']}\t{i['stu_gender']}\t{i['stu_class']}\n")
#     print('存档成功')
#
# def load():
#     # 用来读档
#     global students
#     students=[]
#     with open('d:/PythonProject/record.txt','r',encoding='utf8') as f:
#         for line in f:
#             line=line.strip()
#             tokens=line.split('\t')
#             if len(tokens)!=4:
#                 print('存档格式有问题')
#                 continue
#             student={
#                 'stu_id':tokens[0],
#                 'stu_name':tokens[1],
#                 'stu_gender':tokens[2],
#                 'stu_class':tokens[3]
#             }
#             students.append(student)
#     print(f'共加载了{len(students)}条数据')
#
#
# def add():
#     print('添加学生开始')
#     id=input('请输入学生的学号:')
#     name=input('请输入学生的姓名:')
#     gender=input('请输入学生的性别:')
#     if gender not in ('男','女'):
#         print('输入有误')
#         return
#     stu_class=input('请输入学生的班级:')
#     student={
#         'stu_id':id,
#         'stu_name':name,
#         'stu_gender':gender,
#         'stu_class':stu_class
#     }
#     global students
#     students.append(student)
#     show()
#     print('添加学生结束')
#     save()
#
# def show():
#     for i in students:
#         print(f"学号:{i['stu_id']},姓名:{i['stu_name']},性别:{i['stu_gender']},班级{i['stu_class']}")
#     print(f'共展示了{len(students)}条信息')
#     return
#
# def delete():
#     print('删除开始')
#     id=input('请输入要删除学生的学号')
#     global students
#     for i in students:
#         if i['stu_id']==id:
#             print(f"删除该学号:{i['stu_id']},姓名:{i['stu_name']},性别:{i['stu_gender']},班级{i['stu_class']}的学生")
#             students.remove(i)
#     print('删除成功')
#     save()
# def find():
#     print('查找学生开始')
#     id=input('请输入要查找学生的学号')
#     for i in students:
#         if i['stu_id']==id:
#             print('查找成功')
#             print(f"学号:{i['stu_id']},姓名:{i['stu_name']},性别:{i['stu_gender']},班级{i['stu_class']}")
#             break
#     print('查找学生结束')
#
#
# def main():
#     load()
#     print('----------------')
#     print('-----欢迎你------')
#     print('----------------')
#     while True:
#         menu()
#         choice=input('请输入你的选择:')
#         if choice=='1':
#             add()
#         elif choice=='2':
#             show()
#         elif choice=='3':
#             delete()
#         elif choice=='4':
#             find()
#         elif choice=='0':
#             print('byebye')
#             sys.exit(0)
#         else:
#             print('输入有误,请重新输入')
#
# main()